feat: Keploy schema-match sample app#99
Conversation
Signed-off-by: Harshit Pathak <harshit07pathak@gmail.com>
Signed-off-by: Harshit Pathak <harshit07pathak@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a new Python sample application called "Python Schema Match" to demonstrate JSON schema validation capabilities with Keploy. The application is a socket-based HTTP server that provides multiple endpoints with various JSON response structures to test schema matching, including nested objects, arrays, edge cases, and data type validation.
Changes:
- Added a socket-based HTTP server (
app.py) with 12 endpoints serving different JSON response patterns - Added a test version of the server (
app-test.py) with intentionally modified responses to demonstrate schema validation failures - Added an endpoint checker utility (
check-endpoints.py) to test all endpoints automatically - Added comprehensive documentation (
README.md) with setup instructions, API documentation, and Keploy integration guide
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python-schema-match/app.py | Original HTTP server implementation with 12 endpoints for recording test cases |
| python-schema-match/app-test.py | Modified HTTP server with schema variations to test compatibility (5 intentional failures) |
| python-schema-match/check-endpoints.py | Utility script to automatically test all 12 endpoints |
| python-schema-match/README.md | Comprehensive documentation covering setup, usage, and expected test results |
Comments suppressed due to low confidence (12)
python-schema-match/app.py:136
- The socket.timeout exception is silently caught without any logging. This makes debugging timeout issues difficult. Consider adding at least a debug log message when timeouts occur, especially since client_socket.settimeout(5.0) is explicitly set. This would help diagnose connection issues during testing.
except socket.timeout:
pass
python-schema-match/check-endpoints.py:32
- The unused variable 'body' is read from the response but never used. This could be removed to clean up the code unless it's intended for future functionality.
body = response.read().decode('utf-8')
python-schema-match/app-test.py:8
- According to the comment on line 6, the expected results are "PASS: 7" and "FAIL: 3". However, the RESPONSES dictionary contains 12 endpoints (endpoints 1-12 in comments), not 10. The comments indicate endpoints 4, 5, 6, 11, and 12 should fail (5 failures), but the documentation states only 3 failures. This inconsistency between the expected results comment and the actual test data needs to be resolved.
EXPECTED RESULTS (Total 10):
PASS: 7
FAIL: 3 (Missing Field, Type Mismatch, Hierarchy Mismatch)
python-schema-match/app.py:151
- The error handling logic for port binding is flawed. If the port is already in use, the code waits 2 seconds and then attempts to bind again on the same port without verifying it's actually free. This will likely fail again with the same OSError. Consider either using a different port, implementing a retry loop with proper verification, or letting the error propagate to inform the user to free the port.
server_socket.bind(('0.0.0.0', PORT))
except OSError:
print("Port in use, waiting...")
time.sleep(2)
server_socket.bind(('0.0.0.0', PORT))
python-schema-match/app.py:11
- The 'sys' module is imported but never used in the code. Consider removing this unused import to clean up the code.
import sys
python-schema-match/check-endpoints.py:32
- Variable body is not used.
body = response.read().decode('utf-8')
python-schema-match/app-test.py:14
- Import of 'time' is not used.
import time
python-schema-match/app.py:11
- Import of 'sys' is not used.
import sys
python-schema-match/check-endpoints.py:3
- Import of 'sys' is not used.
import sys
python-schema-match/app.py:135
- 'except' clause does nothing but pass and there is no explanatory comment.
except socket.timeout:
python-schema-match/app-test.py:162
- Instance of context-manager class socket is closed in a finally block. Consider using 'with' statement.
client_socket.close()
python-schema-match/app.py:140
- Instance of context-manager class socket is closed in a finally block. Consider using 'with' statement.
client_socket.close()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@pathakharshit Please add readme which can be followed. |
This pull request expands the test coverage and complexity of the schema matching application by introducing two new complex endpoints (
/complex/userand/complex/product) and updating related test and check files. It also improves HTTP response handling by explicitly closing connections.New complex endpoint support:
/complex/userand/complex/productendpoints with nested and array structures toapp.pyfor more comprehensive schema testing.check-endpoints.pyto include the new complex endpoints, ensuring they are checked during validation.Test coverage enhancements:
/complex/userand/complex/productinapp-test.py, demonstrating schema mismatches such as type errors and missing keys.HTTP response improvements:
handle_requestto includeConnection: close, ensuring proper socket closure after each request.